package com.test.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Enumeration;

/**
 * Created by jinyb on 2017/4/12.
 */
public class LoginFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Enumeration<String> contextPara = filterConfig.getInitParameterNames();
        while (contextPara.hasMoreElements()) {

            String key = contextPara.nextElement();
            System.out.println("filter---" + key + "=" + filterConfig.getInitParameter(key));
        }
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("LoginFilter-doFilter");


        if (servletRequest instanceof HttpServletRequest) {
            HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
            System.out.println("query-" + httpServletRequest.getQueryString());
        }
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {
        System.out.println("doFilter-destroy");
    }
}
